// pages/index-inside-page/dangerDetail/dangerDetail.js

import {
    reqAuditDetails
} from "../../../request/api"
import {
    showMsg
} from '../../../utils/config.js'

var app = getApp()

Page({

    /**
     * 页面的初始数据
     */
    data: {
        navHeight: app.globalData.navHeight + 'px', //头部距离
        handleContent: '',
        steps: [],
        active: 1
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            dangerInfo: JSON.parse(options.dangerInfo)
        })
        this.getAuditDetails()
    },
    // 获取隐患记录
    async getAuditDetails() {
        console.log(this.data.dangerInfo, "this.data.dangerInfo");
        let res = await reqAuditDetails(this.data.dangerInfo.id)
        if (res.code !== 20000) return showMsg(res.message)
        let {
            rows
        } = res.data
        let fileList = []
        let steps = []
        if (rows.length) {
            rows.forEach((item, index) => {
                if (item.status == 2 && index == 0 && item.fileList != null && item.fileList.length) {
                    item.fileList.forEach(item => {
                        fileList.push({
                            url: item
                        })
                    })
                }
                steps.push({
                    text: item.status == 2 ? '上报内容' : item.status == 3 ? '隐患审核'+' '+item.handleResult : item.status == 4 ? '处理工单'+' '+item.handleResult : item.status == 5 ? '处理审核'+' '+item.handleResult : '处理完成',
                    // text: item.status == 1 ? '隐患上报' : item.status == 2 ? '隐患审核' : item.status == 3 ? '处理工单' : item.status == 4 ? '处理审核' : '处理完成',
                    desc: item.handleContent,
                    inactiveIcon: 'location-o',
                    activeIcon: 'success',
                })
            })
            if(this.data.dangerInfo.status==5){
                steps.push({
                    text: '已完成',
                    desc: '',
                    inactiveIcon: 'location-o',
                    activeIcon: 'success',
                })
            }
            this.setData({
                steps,
                active: steps.length - 1,
                // handleContent: rows[0].handleContent,
                // handleResult: rows[0].handleResult,
                // status: rows[0].status,
                fileList,
            })
        }
    },

    // 审核
    onExamine() {
        wx.navigateTo({
            url: `/packageA/pages/index-inside-page/handleDanger/handleDanger?dangerInfo=${JSON.stringify(this.data.dangerInfo)}`,
        })
    }
})